package com.zzyl.nursing.controller.member;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zzyl.common.UserThreadLocal;
import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.vo.ReservationVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.service.IReservationService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 预约信息Controller
 * 
 * @author ruoyi
 * @date 2025-08-02
 */
@RestController
@RequestMapping("/member/reservation")
@Api(tags = "C端-参加预约接口")
public class ReservationController extends BaseController
{
    @Autowired
    private IReservationService reservationService;

    /**
     * 分页查询预约
     */
//    @GetMapping("/page")
//    @ApiOperation("分页查询预约")
//    public TableDataInfo<List<Reservation>> list(Reservation reservation)
//    {
//        startPage();
//        List<Reservation> list = reservationService.selectReservationList(reservation);
//        return getDataTable(list);
//    }


    /**
     * 获取预约信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('nursing:reservation:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取预约信息详细信息")
    public R<Reservation> getInfo(@ApiParam(value = "预约信息ID", required = true)
            @PathVariable("id") Long id)
    {
        return R.ok(reservationService.selectReservationById(id));
    }

    /**
     * 新增预约
     */
    @PreAuthorize("@ss.hasPermi('nursing:reservation:add')")
    @Log(title = "预约信息", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增预约信息")
    public AjaxResult add(@ApiParam(value = "预约信息实体", required = true) @RequestBody Reservation reservation)
    {
        return toAjax(reservationService.insertReservation(reservation));
    }
    /**
     * 2.1 查询当天取消预约数量
     * @param
     */
    @GetMapping("/cancelled-count")
    @ApiOperation("查询当天取消预约数量")
    public AjaxResult  getCancelledCountForToday(){
        int countForToday = reservationService.getCancelledCountForToday();
        return AjaxResult.success( countForToday);
    }
    /**
     * 查询每个时间段剩余预约次数
     * @param time
     */
    @GetMapping("/countByTime")
    @ApiOperation("查询每个时间段剩余预约次数")
    public R<List<ReservationVo>>countByTime(@ApiParam(value = "时间", required = true) Long time){
     List<ReservationVo> reservationVos = reservationService.countByTime(time);
     return R.ok(reservationVos);
    }
    /**
     * 取消预约
     * @param id
     */
    @PutMapping("/{id}/cancel")
    @ApiOperation("取消预约")
    public AjaxResult cancel(@ApiParam(value = "预约信息ID", required = true) @PathVariable("id") Long id){
        return toAjax(reservationService.cancelReservation(id));
    }

}
